﻿using CoreLibrary;
using CoreLibrary.Security;
using IBBI.DataBase.Persistent;

namespace IBBI.DataBase.Obj {

    public sealed class CreateUserRequest {

        public static CreateUserRequest Instance {
            get {
                return new CreateUserRequest();
            }
        }

        private readonly User _user;

        private CreateUserRequest() {
            _user = new User();
        }

        public User Build() {
            Asserts.NotBlank(_user.Password,  "Password can not be empty");
            Asserts.NotBlank(_user.Email,     "Email Address can not be empty");
            return _user;
        }

        public CreateUserRequest WithFirstName(string firstName) {
            _user.FirstName = Util.GetString(firstName);
            return this;
        }

        public CreateUserRequest WithMiddleName (string middleName) {
            _user.MiddleName = Util.GetString(middleName);
            return this;
        }

        public CreateUserRequest WithLastName (string lastName) {
            _user.LastName = Util.GetString(lastName);
            return this;
        }

        public CreateUserRequest WithTitle(string title) {
            _user.Title = Util.GetString(title);
            return this;
        }

        public CreateUserRequest WithPassword(string password) {
            _user.Password = Util.GetString(Hasher.SHA256Hex(password));
            return this;
        }

        public CreateUserRequest WithAccountRole(int role) {
            _user.Role = role;
            return this;
        }

        public CreateUserRequest WithEmail(string email) {
            _user.Email = Util.GetString(email);
            return this;
        }

        public CreateUserRequest WithEnabled(bool enabled) {
            _user.Enabled = enabled;
            return this;
        }

    }
}